package com.cashmama.market.api.application.controller.user.verfifycode.request;

import com.cashmama.market.api.infras.enums.error.VerifyCodeErrorCodeEnum;
import com.cashmama.market.api.infras.enums.message.VerifyCodeTypeEnum;
import com.cashmama.market.api.infras.exception.ApplicationException;
import com.cashmama.market.api.infras.utils.StringUtils;
import com.fqgj.common.api.ParamsObject;
import org.hibernate.validator.constraints.NotBlank;

/**
 * @program: market-api
 * @description 验证码短信
 * @author: frank
 * @create: 2019-12-20 12:02
 **/
public class VerifyCodeSendRequest extends ParamsObject {

    /**
     * 验证码接收手机号
     */
    private String mobile;

    /**
     * 验证码类型
     * register : 注册
     * login : 快捷登录
     * forgetPassword : 找回密码
     * updatePassword : 修改密码
     * bindDevice : 设备绑定
     */
    @NotBlank(message = "Type cannot be empty")
    private String type;

    private String imgVerifyCode;

    private String imgCodeId;

    @Override
    public void validate() {
        if (!VerifyCodeTypeEnum.getNameList().contains(type)) {
            throw new ApplicationException(VerifyCodeErrorCodeEnum.VERIFYCODE_TYPE_NOT_EXIST);
        }

        if (StringUtils.isEmpty(mobile)) {
            if (VerifyCodeTypeEnum.VERIFY_TYPE_ADVANCE_IDENTITY_CHECK.getName().equals(type)) {
                throw new ApplicationException("Aadhaar number cannot be empty");
            }
            throw new ApplicationException("Mobile number cannot be empty");
        }
    }

    public String getMobile() {
        return mobile;
    }

    public VerifyCodeSendRequest setMobile(String mobile) {
        this.mobile = mobile;
        return this;
    }

    public String getType() {
        return type;
    }

    public VerifyCodeSendRequest setType(String type) {
        this.type = type;
        return this;
    }

    public String getImgVerifyCode() {
        return imgVerifyCode;
    }

    public VerifyCodeSendRequest setImgVerifyCode(String imgVerifyCode) {
        this.imgVerifyCode = imgVerifyCode;
        return this;
    }

    public String getImgCodeId() {
        return imgCodeId;
    }

    public VerifyCodeSendRequest setImgCodeId(String imgCodeId) {
        this.imgCodeId = imgCodeId;
        return this;
    }
}
